package com.aos.erp.message.rpc;

import com.aos.erp.common.bean.PageBean;
import com.aos.erp.common.bean.ResultEntity;
import com.aos.erp.message.dto.MessageRecordDTO;
import com.aos.erp.message.dto.MessageRecordItemDTO;
import com.aos.erp.message.dto.MessageRecordWaitPushItemDTO;
import com.aos.erp.message.model.vo.MRConditionVo;
import com.aos.erp.message.service.MessageRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@Api(tags = {"服务接口：消息记录接口"})
@RestController
@RequestMapping("/service/message/record")
public class RpcMessageRecordController {

    @Autowired
    MessageRecordService messageRecordService;

    @ApiOperation(value = "分页查询消息记录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageIndex", value = "当前页", required = true, dataType = "Integer", defaultValue = "1", paramType = "Query"),
            @ApiImplicitParam(name = "pageSize", value = "每页大小", required = true, dataType = "Integer", defaultValue = "20", paramType = "Query"),
            @ApiImplicitParam(name = "mrContent", value = "推送内容", dataType = "String", paramType = "Query"),
            @ApiImplicitParam(name = "pushType", value = "推送方式(app:APP；wx_public:微信公众号；wx_applet:微信小程序；sms_timely:及时短信)", dataType = "PushType", paramType = "Query"),
            @ApiImplicitParam(name = "pushStatus", value = "推送状态：push_no为未发送；push_yes为已发送；push_stop为暂停发送", dataType = "PushStatus", paramType = "Query"),
            @ApiImplicitParam(name = "fromTime", value = "发送开始时间", dataType = "String", paramType = "Query"),
            @ApiImplicitParam(name = "toTime", value = "发送截止时间", dataType = "String", paramType = "Query"),
            @ApiImplicitParam(name = "driverSchoolId", value = "驾校ID", dataType = "Long", paramType = "Query")
    })
    @PostMapping("/listPage")
    public PageBean<MessageRecordItemDTO> listTemplate(@RequestBody MRConditionVo params) {
        return messageRecordService.findByPage(params);
    }

    @ApiOperation(value = "分页查询待发消息记录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageIndex", value = "当前页", required = true, dataType = "Integer", defaultValue = "1", paramType = "Query"),
            @ApiImplicitParam(name = "pageSize", value = "每页大小", required = true, dataType = "Integer", defaultValue = "20", paramType = "Query"),
            @ApiImplicitParam(name = "mrContent", value = "推送内容", dataType = "String", paramType = "Query"),
            @ApiImplicitParam(name = "pushType", value = "推送方式(app:APP；wx_public:微信公众号；wx_applet:微信小程序；sms_timely:及时短信)", dataType = "PushType", paramType = "Query"),
            @ApiImplicitParam(name = "fromTime", value = "开始时间", dataType = "String", paramType = "Query"),
            @ApiImplicitParam(name = "toTime", value = "截止时间", dataType = "String", paramType = "Query"),
            @ApiImplicitParam(name = "driverSchoolId", value = "驾校ID", dataType = "Long", paramType = "Query")
    })
    @PostMapping("/listWaitPushRecord")
    public PageBean<MessageRecordWaitPushItemDTO> listWaitPushRecord(@RequestBody MRConditionVo params) {
        return messageRecordService.findWaitSendByPage(params);
    }

    @ApiOperation(value = "查看推送消息详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dataId", value = "消息记录ID", required = true, dataType = "Long", paramType = "Query")
    })
    @PostMapping("/detail")
    public MessageRecordDTO detailNotice(@RequestBody Long dataId){
        return messageRecordService.getRecordDetail(dataId);
    }

    @ApiOperation(value = "删除消息记录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", value = "记录ID：id1,id2,id3", required = true, dataType = "Long", paramType = "Query")
    })
    @PostMapping("/delete")
    public ResultEntity deleteRecord(@RequestBody String ids) throws Exception{
        messageRecordService.deleteRecord(ids);
        return ResultEntity.success("删除成功");
    }
}
